<template>
  <div class="top">
    <div class="content">
      <!-- 左侧 -->
      <div class="left" @click="goHome">
        <img src="@/assets/images/logo.png" />
        <p class="v-link">一医通 预约挂号统一平台</p>
      </div>
      <div class="right">
        <p class="help v-link">帮助中心</p>
        <!-- 如果没有用户名字：显示登录注册 -->
        <p class="login v-link" @click="login" v-if="!userStore.userInfo.name">登录/注册</p>
        <!-- 如果有用户信息就展示用户信息 -->
        <el-dropdown v-else>
          <span class="el-dropdown-link">
            {{userStore.userInfo.name}}
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="toCertification">实名认证</el-dropdown-item>
              <el-dropdown-item @click="toOrder">挂号订单</el-dropdown-item>
              <el-dropdown-item>就诊人管理</el-dropdown-item>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from "vue-router";
// @ts-ignore
import useUserStore from "@/store/modules/user.ts";
import { ArrowDown } from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
const userStore = useUserStore();
const router = useRouter();
const goHome = () => {
  router.push("/");
};
const toCertification=()=>{
  router.push('/user/certification')
}
const toOrder=()=>{
  router.push('/user/order')
}
// 登录
const login = () => {
  userStore.visible = true;
};
// 退出登录
const logout = () => {
  ElMessageBox.confirm("确定退出登录吗？", "Warning", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning"
  })
    .then(() => {
      userStore.clearUserInfo();
      router.push("/");
      ElMessage({
        type: "success",
        message: "退出登录成功"
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消退出登录"
      });
    });
};
</script>

<style lang="scss" scoped>
.v-link {
  color: #666;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
}
.top {
  position: fixed;
  z-index: 999;
  display: flex;
  justify-content: center;
  width: 100%;
  height: 70px;
  background-color: #fff;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  .content {
    display: flex;
    justify-content: space-between;
    width: 1200px;
    height: 70px;
    background-color: #fff;
    .left {
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }
      p {
        font-size: 22px;
        color: #4490f1;
      }
    }
    .right {
      display: flex;
      align-items: center;
      justify-content: space-between;
      cursor: pointer;
      .help {
        margin-right: 10px;
      }
      p {
        font-size: 14px;
        transition: all 0.2s;
        &:hover {
          color: #4490f1;
        }
      }
    }
  }
}
</style>